// Get.ts

import { ExecutionContext, SetMetadata } from "@nestjs/common";
import { RouteDefinition } from "./interface/message.interface";


export const MyApi = (path: string): MethodDecorator => {
  return (target, propertyKey: string): void => {
    // console.log(path);
    // console.log(Reflect.hasMetadata('routes', target.constructor));
    if (!Reflect.hasMetadata('routes', target.constructor)) {
        // console.log(1)
      Reflect.defineMetadata('routes', [], target.constructor);
    }

    const routes = Reflect.getMetadata('routes', target.constructor) as Array<RouteDefinition>;
    

    routes.push({
      requestMethod: 'myapi',
      path,
      methodName: propertyKey
    });
    // console.log(routes);
    Reflect.defineMetadata('routes', routes, target.constructor);
  };
};


export const ROLES_KEY = 'roles';
export const Roles = (...roles) => SetMetadata(ROLES_KEY, roles);
